<template>
	<view class="home-layout">
		<custom-nav-bar></custom-nav-bar>
		<view class="swiper-list">
			<swiper :indicator-dots="true" class="swiper">
				<swiper-item class="swiper-item" v-for="(item,index) in scrllMeunListStep">
					<!-- <strong>{{index}}</strong> -->
					<up-grid :border="false" col="4">
						<up-grid-item v-for="(i,key) in getGridItemStep(index)" @click="meunItemHandle(i)"
							:key="i.icon">
							<view class="icon-bg"><text class="icon custom-icon nav-icon" :class="i.icon"></text></view>
							<text class="grid-text">{{i.name}}</text>
						</up-grid-item>
					</up-grid>
					<up-toast ref="uToastRef" />
				</swiper-item>
			</swiper>
		</view>
		<view class="bulletin-board">
			<u-notice-bar :text="bulletin" direction="column" :showGetMore="true" url="pages/index/index">
			</u-notice-bar>
		</view>
		<view class="massive-job-box">
			<image src="../../static//images/massive-job.jpg" alt="" />
		</view>
		<view class="list-box">
			<view class="list-box-tabs">
				<u-tabs :list="listTabs">
					<template #right>
						<view style="padding-left: 4px; color: #7d99f5;">
							查看更多
						</view>
					</template>
				</u-tabs>
				<view class="position-card-list">
					<PositionCard v-for="item in 5" :key="item" :card-data="cardDataList"></PositionCard>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import CustomNavBar from '../../competents/custom-nav-bar/custom-nav-bar.vue'
	import PositionCard from '../../competents/position-card/position-card.vue'
	import {
		computed,
		reactive,
		ref,
		onMounted
	} from 'vue';
	import {
		counterStore
	} from '@/store/counter.js'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	// import { log } from 'util';
	onMounted(() => {
		// console.log(getGridItemStep.value,' 22121')
	})
	const scrollMeunList =
		reactive([{
				// thumb: "https://cdn.uviewui.com/uview/menu/11.png",
				icon: 'custom-icon-gongzuo',
				name: '找工作'
			},
			{
				// thumb: "https://cdn.uviewui.com/uview/menu/9.png",
				icon: 'custom-icon-rencai',
				name: '找人才'
			},
			{
				// thumb: "https://cdn.uviewui.com/uview/menu/11.png",
				icon: 'custom-icon-qiye',
				name: '搜企业'
			},
			{
				// thumb: "https://cdn.uviewui.com/uview/menu/9.png",
				icon: 'custom-icon-zhaopin',
				name: '急聘专区'
			},
			{
				// thumb: "https://cdn.uviewui.com/uview/menu/11.png",
				icon: 'custom-icon-zhaopinhui',
				name: '招聘会'
			},
			{
				// thumb: "https://cdn.uviewui.com/uview/menu/9.png",
				icon: 'custom-icon-yishenqing',
				name: '新闻咨询'
			}
		]);
	const scrllMeunListStep = computed(() => {
		return Math.ceil(scrollMeunList.length / 4)
	})
	console.log(scrllMeunListStep.value, 'scrllMeunListStep')
	const getGridItemStep = computed(() => {
		return (key) => {
			const index = key + 1
			const len = scrollMeunList.length
			const step = index * 4
			if (step > len) {
				// return len - (step - 4)
				return scrollMeunList.slice(key === 0 ? 0 : step - 4, scrollMeunList.length)
			}
			return scrollMeunList.slice(key === 0 ? 0 : step - 4, step)
		}
	})
	// 创建对子组件的引用  
	const uToastRef = ref(null);
	// 定义方法  
	const meunItemHandle = (item) => {
		// if (uToastRef.value) {  
		//     uToastRef.value.success(`点击了第${item.name}`); // 注意：这里加1是因为通常我们是从第1个开始计数的  
		// }  
	};
	const indicator = ref(true)
	const bulletin = ref([
		'公告信息测试',
		'公告信息:鸡你太美',
		'公告信息 小黑子',
		'公告信息 title1',
		'公告信息 title2',
	])
	const text1 = ref('uview-plus UI众多组件覆盖开发过程的各个需求，组件功能丰富，多端兼容。让您快速集成，开箱即用');

	const counter = counterStore()
	const handleCount = () => {
		counter.increment()
	}
	const listTabs = reactive([{
			name: '综合'
		},
		{
			name: '最新'
		},
		{
			name: '附近'
		},
	]);
	onLoad(() => {
		console.log('this is page index-')
	})
</script>

<style lang="scss" scoped>
	.home-layout {
		width: 750rpx;
		padding-top: 100rpx;
		background: linear-gradient(to right top, #b8d2d845, #fff);

		.swiper-list {
			margin-top: 100rpx;

			.swiper {
				height: 190rpx;

				.swiper-item {
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}

		::v-deep .u-scroll-list {
			margin: 0 35rpx;
			border-radius: 10rpx;
			background-color: #E6EDF1;
		}

		.bulletin-board {
			width: 100%;
			// height: 47rpx;

		}

		.massive-job-box {
			margin: 20rpx 0;

			image {
				width: 100%;
				height: 115rpx;
				border-radius: 10rpx;
			}
		}
	}

	.meun-item {
		text-align: center;
		// width: 50rpx;
		// height: 50rpx;
		margin: 0 5rpx;

	}

	.meun-item-img {
		width: 170rpx;
		height: 170rpx;
	}

	.icon-bg {
		background: linear-gradient(to right, #f1f2fe, #d8defb);
		width: 100rpx;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 20%;
	}

	.nav-icon {
		font-size: 50rpx;
		color: #3357f3;
	}

	.bulletin-board ::v-deep .u-notice-bar {
		border-radius: 10rpx;
		background: #ffffff !important;
	}
</style>